package me.jiatao.hilt.scopes

import android.util.Log
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ActivityComponent
import dagger.hilt.android.components.ActivityRetainedComponent
import dagger.hilt.android.scopes.ActivityRetainedScoped
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

class ActivityClassA {
    fun hello() {
        Log.e("ActivityClassA", "------ ActivityClassA hello  ------")
    }
}

class ActivityClassB(private val appClassA: AppClassA) {
    fun hello() {
        appClassA.hello()
        Log.e("ActivityClassB", "------ ActivityClassB hello  ------")
    }
}


@Module
@InstallIn(ActivityRetainedComponent::class)
class ActivityScopes {

    @ActivityRetainedScoped
    @Provides
    fun provideActivityClassA(): ActivityClassA {
        return ActivityClassA()
    }

    /**
     *  @ActivityRetainedScoped 使用 @Singleton 提供的实例
     */
    @ActivityRetainedScoped
    @Provides
    fun provideActivityClassB(appClassA: AppClassA): ActivityClassB {
        return ActivityClassB(appClassA)
    }
}